--[[
    function: 查询设备信息
	author: jim_sun
    wiki: 
    api:
    example:
        curl 'URI/device/device_query?type=xxxxxxxxx&token=xxxxxxx' 
        return
        {
            "status":1,
            "errcode":"",
            "msg":"",
            "data":{
        
            },
        }

]]
local args = ngx.req.get_uri_args()
local token = args.token
local user_id = nil

if not common_util.check_args(1, token) then
    common_util.exit(200, 0, nil, "101", "token is missing")
end

local user_id = common_util.get_user_id_by_token(token)
if not user_id then
    common_util.exit(200, 0, nil, "105", "token is ....")
end

local query_band_status = function()
    local gateway_id = args.gateway_id
    if not common_util.check_args(1, gateway_id) then
        common_util.exit(200, 0, nil, "101", "gateway_id is missing")
    end
    local sql = "select status from tb_gateway_info where ".." gateway_id="..ngx.quote_sql_str(gateway_id).." limit 1"
    local data,bool = common_util.db_query_common(sql,common_config.db_user_info_addr)
    if false == bool  then
        --connection:over()
        common_util.exit(200, 0, nil, "500", "mysql is error")
    end
    if next(data) then
        return data[1]
    end
    return nil
end

local method = {
    ["query_band_status"] = query_band_status, --获取绑定网关状态
}

if not method[args.type] then
    common_util.exit(200, 0, nil, "101", "type is missing")
end

local res_data = method[args.type]() 

if not res_data then
    common_util.exit(200, 0, res_data, "", "error")
end
common_util.exit(200, 1, res_data, "", "success")



